<?php

class Core_Backend_Component_Promotion_View_Friendlink_Create extends Core_Backend_Share_View_Form {

    protected function buildToolbar($toolbar) {
    	$group = $toolbar->createGroup('back');
        $group->addLink($this->getHistoryUrl('promotion/friendlink/index'), $this->__('share.button.back'));
        if($this->getIdentity()->isAllowAction('promotion_friendlink_edit')){
	        $group = $toolbar->createGroup('save');
	        $group->addButton($this->__('share.button.submit'))
	                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(array('status'=>'pending'), 'save') . "')");
	        $group->addButton($this->__('share.button.save'))
	                ->bindEvent('click', "Kdf.Ui.getForm('" . $this->getForm()->getId() . "').submit('" . $this->getUrl(array('status'=>'draft'), 'save') . "')");
        }
        parent::buildToolBar($toolbar);
    }

    public function buildForm($form) {
        $entity = $this->getModel(NULL);
        $form->setAction($this->getUrl())
                ->setId('friendlink_form')
                ->addHiddenField('id', 'friendlink[id]');
        $form->addTextboxField($this->__('share.label.title'), 'title', 'friendlink[title]', TRUE)
                ->addMultiRule('required');
        $form->addTextboxField($this->__('share.label.url'), 'url', 'friendlink[url]', TRUE)
                ->addRequiredRule();
        $form->addFileBrowserField($this->__('catalogue.label.picture'), 'picture', 'friendlink[picture]')
				->setPath('pub/media/friendlink')
				->setFileType('image')
				->setCallback('selectProductPictute');
        if (!is_null($entity)) {
            $form->bindData($entity->getAllData());
        }
        parent::buildForm($form);
    }

}

